import pandas as pd

def clean_commit_data(api_data):
    data = []
    for _ in api_data:
        temp_obj = {}
        temp_obj['sha'] = _['sha']
        temp_obj['url'] = _['url']
        temp_obj['node_id'] = _['node_id']
        temp_obj['html_url'] = _['html_url']
        temp_obj['commit_message'] = _['commit']['message']

        temp_obj['comments_url'] = _['comments_url']
        temp_obj['comment_count'] = _['commit']['comment_count']
        temp_obj['commit_date'] = _['commit']['committer']['date']
        
        temp_obj['committer_name'] = _['commit']['committer']['name']
        temp_obj['committer_email'] = _['commit']['committer']['email']
        
        temp_obj['committer_login'] = _['committer']['login'] if _['committer'] else ''
        temp_obj['committer_url'] = _['committer']['url'] if _['committer'] else ''
        temp_obj['committer_followers_url'] = _['committer']['followers_url'] if _['committer'] else ''
        temp_obj['committer_following_url'] = _['committer']['following_url'] if _['committer'] else ''

        data.append(temp_obj)
    return pd.DataFrame(data)

def clean_commitcomment_data(api_data):
    data = []
    for _ in api_data:
        temp_obj = {}
        temp_obj['url'] = _['url']
        temp_obj['node_id'] = _['node_id']
        temp_obj['html_url'] = _['html_url']
        temp_obj['body'] = _['body']

        temp_obj['commit_id'] = _['commit_id']
        temp_obj['user_login'] = _['user']['login'] if _['user'] else ''
        temp_obj['user_url'] = _['user']['url'] if _['user'] else ''

        temp_obj['created_at'] = _['created_at']
        temp_obj['updated_at'] = _['updated_at']

        data.append(temp_obj)
    return pd.DataFrame(data)

def clean_issue_data(api_data):
    data = []
    for _ in api_data:
        temp_obj = {}
        temp_obj['url'] = _['url']
        temp_obj['node_id'] = _['node_id']
        temp_obj['title'] = _['title']
        temp_obj['body'] = _['body']

        temp_obj['user_login'] = _['user']['login'] if _['user'] else ''
        temp_obj['user_url'] = _['user']['url'] if _['user'] else ''

        temp_obj['comments'] = _['comments']

        temp_obj['created_at'] = _['created_at']
        temp_obj['updated_at'] = _['updated_at']

        data.append(temp_obj)
    return pd.DataFrame(data)

def clean_issuecomment_data(api_data):
    data = []
    for _ in api_data:
        temp_obj = {}
        temp_obj['url'] = _['url']
        temp_obj['node_id'] = _['node_id']
        temp_obj['body'] = _['body']

        temp_obj['user_login'] = _['user']['login'] if _['user'] else ''
        temp_obj['user_url'] = _['user']['url'] if _['user'] else ''

        temp_obj['created_at'] = _['created_at']
        temp_obj['updated_at'] = _['updated_at']

        temp_obj['issue_url'] = _['issue_url']

        data.append(temp_obj)
    return pd.DataFrame(data)

def clean_PR_data(api_data):
    data = []
    for _ in api_data:
        temp_obj = {}
        temp_obj['url'] = _['url']
        temp_obj['review_comments_url'] = _['review_comments_url']
        temp_obj['title'] = _['title']
        temp_obj['created_at'] = _['created_at']

        temp_obj['PR_user_login'] = _['user']['login'] if _['user'] else ''
        temp_obj['PR_user_url'] = _['user']['url'] if _['user'] else ''
        temp_obj['merge_commit_sha'] = _['merge_commit_sha']

        data.append(temp_obj)
    return pd.DataFrame(data)